## Create Figure 1

## Loading packages
library(readxl)
library(tidyverse)
library(lubridate)
library(sf)
library(foreign)
library(haven)

## Load data
dta = read_stata("dta.dta")

schools_per_year = dta %>%
  mutate(n = 1) %>%
  group_by(school_year, district) %>%
  summarise(n_school = sum(n))

schools_received = dta %>%
  left_join(., schools_per_year, by = c("district", "school_year")) %>%
  group_by(school_year, district, n_school) %>%
  summarise(bmp_received = sum(bmp_received, na.rm = TRUE)) %>%
  mutate(share_schools_bmp = bmp_received/n_school*100)

## Panel A
share_schools_bmp1 = ggplot(schools_received %>% filter(district == 1), 
                            aes(x = factor(school_year), y = share_schools_bmp)) +
  geom_bar(stat = "identity",color="black", fill="gray") +
  geom_text(aes(label=
                  paste0(I(round(share_schools_bmp, digits = 2)), "%")), 
            position=position_dodge(width=0.9), vjust=-0.45, size = 2.5) +
  scale_x_discrete(labels= c("2011-2012", "2012-2013", "2013-2014", "2014-2015",
                             "2015-2016", "2016-2017", "2017-2018", "2018-2019",
                             "2019-2020")) +
  labs(x = "School Year", y = "Share of Schools Receiving \n 1+ BMP Projects") +
  scale_y_continuous(limits = c(0, 50), labels = function(x) paste0(x, "%"))+
  theme_bw() +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"),
        axis.text.x = element_text(angle = 45, hjust=1))

## Panel B
share_schools_bmp2 = ggplot(schools_received %>% filter(district == 2), 
                            aes(x = factor(school_year), y = share_schools_bmp)) +
  geom_bar(stat = "identity",color="black", fill="gray") +
  geom_text(aes(label=
                  paste0(I(round(share_schools_bmp, digits = 2)), "%")), 
            position=position_dodge(width=0.9), vjust=-0.45, size = 2.5) +
  scale_x_discrete(labels= c("2011-2012", "2012-2013", "2013-2014", "2014-2015",
                             "2015-2016", "2016-2017", "2017-2018", "2018-2019",
                             "2019-2020")) +
  labs(x = "School Year", y = "Share of Schools Receiving \n 1+ BMP Projects") +
  scale_y_continuous(limits = c(0, 10), labels = function(x) paste0(x, "%"))+
  theme_bw() +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"),
        axis.text.x = element_text(angle = 45, hjust=1))

## Panel C
share_schools_bmp3 = ggplot(schools_received %>% filter(district == 3), 
                            aes(x = factor(school_year), y = share_schools_bmp)) +
  geom_bar(stat = "identity",color="black", fill="gray") +
  geom_text(aes(label=
                  paste0(I(round(share_schools_bmp, digits = 2)), "%")), 
            position=position_dodge(width=0.9), vjust=-0.45, size = 2.5) +
  scale_x_discrete(labels= c("2011-2012", "2012-2013", "2013-2014", "2014-2015",
                             "2015-2016", "2016-2017", "2017-2018", "2018-2019",
                             "2019-2020")) +
  labs(x = "School Year", y = "Share of Schools Receiving \n 1+ BMP Projects") +
  scale_y_continuous(limits = c(0,70), labels = function(x) paste0(x, "%"))+
  theme_bw() +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"),
        axis.text.x = element_text(angle = 45, hjust=1))

## Panel D
share_schools_bmp4 = ggplot(schools_received %>% filter(district == 4), 
                            aes(x = factor(school_year), y = share_schools_bmp)) +
  geom_bar(stat = "identity",color="black", fill="gray") +
  geom_text(aes(label=
                  paste0(I(round(share_schools_bmp, digits = 2)), "%")), 
            position=position_dodge(width=0.9), vjust=-0.45, size = 2.5) +
  scale_x_discrete(labels= c("2011-2012", "2012-2013", "2013-2014", "2014-2015",
                             "2015-2016", "2016-2017", "2017-2018", "2018-2019",
                             "2019-2020")) +
  labs(x = "School Year", y = "Share of Schools Receiving \n 1+ BMP Projects") +
  scale_y_continuous(limits = c(0,40), labels = function(x) paste0(x, "%"))+
  theme_bw() +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"),
        axis.text.x = element_text(angle = 45, hjust=1))

## Panel E
share_schools_bmp5 = ggplot(schools_received %>% filter(district == 5), 
                            aes(x = factor(school_year), y = share_schools_bmp)) +
  geom_bar(stat = "identity",color="black", fill="gray") +
  geom_text(aes(label=
                  paste0(I(round(share_schools_bmp, digits = 2)), "%")), 
            position=position_dodge(width=0.9), vjust=-0.45, size = 2.5) +
  scale_x_discrete(labels= c("2011-2012", "2012-2013", "2013-2014", "2014-2015",
                             "2015-2016", "2016-2017", "2017-2018", "2018-2019",
                             "2019-2020")) +
  labs(x = "School Year", y = "Share of Schools Receiving \n 1+ BMP Projects") +
  scale_y_continuous(limits = c(0,25), labels = function(x) paste0(x, "%"))+
  theme_bw() +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"),
        axis.text.x = element_text(angle = 45, hjust=1))

## Panel F
share_schools_bmp6 = ggplot(schools_received %>% filter(district == 6), 
                            aes(x = factor(school_year), y = share_schools_bmp)) +
  geom_bar(stat = "identity",color="black", fill="gray") +
  geom_text(aes(label=
                  paste0(I(round(share_schools_bmp, digits = 2)), "%")), 
            position=position_dodge(width=0.9), vjust=-0.45, size = 2.5) +
  scale_x_discrete(labels= c("2011-2012", "2012-2013", "2013-2014", "2014-2015",
                             "2015-2016", "2016-2017", "2017-2018", "2018-2019",
                             "2019-2020")) +
  labs(x = "School Year", y = "Share of Schools Receiving \n 1+ BMP Projects") +
  scale_y_continuous(limits = c(0,40), labels = function(x) paste0(x, "%"))+
  theme_bw() +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"),
        axis.text.x = element_text(angle = 45, hjust=1))

## Panel G
share_schools_bmp7 = ggplot(schools_received %>% filter(district == 7), 
                            aes(x = factor(school_year), y = share_schools_bmp)) +
  geom_bar(stat = "identity",color="black", fill="gray") +
  geom_text(aes(label=
                  paste0(I(round(share_schools_bmp, digits = 2)), "%")), 
            position=position_dodge(width=0.9), vjust=-0.45, size = 2.5) +
  scale_x_discrete(labels= c("2011-2012", "2012-2013", "2013-2014", "2014-2015",
                             "2015-2016", "2016-2017", "2017-2018", "2018-2019",
                             "2019-2020")) +
  labs(x = "School Year", y = "Share of Schools Receiving \n 1+ BMP Projects") +
  scale_y_continuous(limits = c(0,15), labels = function(x) paste0(x, "%"))+
  theme_bw() +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"),
        axis.text.x = element_text(angle = 45, hjust=1))
